Skip to content

ENH: Always do true division on Python 2.X #5439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2013

Conversation

jtratner
Copy link
Contributor

@jtratner jtratner commented Nov 5, 2013

Close #5356.

Note: this version actually forces a / b to always do truediv as well. It's
less complicated to maintain if we do it that way, but it's also possible to
have this a / b use div and a.div(b) use truediv, just might be strange.
This is definitely different from numpy behavior.

We also may need to add the division future import to more places.

Note: this version actually forces `a / b` to always do truediv as well.
It's less complicated to maintain if we do it that way, but it's also
possible to have this `a / b` use div and `a.div(b)` use truediv, just
might be strange. This is definitely different from numpy behavior.

We also may need to add the division future import to more places.
@jreback
Copy link
Contributor

jreback commented Nov 5, 2013

you can't just put the `from future import divisioninpandas/__init.__py`` which AFAIK is always imported.
or is it module level somehow?

@jtratner
Copy link
Contributor Author

jtratner commented Nov 5, 2013

It's module level :-/

@jtratner
Copy link
Contributor Author

jtratner commented Nov 5, 2013

Just want to make it clear that this is the end result on Python 2.X without the future import (working interactively):

In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: arr = np.array([1, 2, 3, 4])

In [4]: arr2 = np.array([5, 3, 2, 1])

In [5]: arr / arr2
Out[5]: array([0, 0, 1, 4])

In [6]: pd.Series(arr) / pd.Series(arr2)
Out[6]:
0    0.200000
1    0.666667
2    1.500000
3    4.000000
dtype: float64

In [7]:

Whereas before this PR:

In [2]: pd.Series(arr) / pd.Series(arr2)
Out[2]:
0    0
1    0
2    1
3    4
dtype: int64

@jreback
Copy link
Contributor

jreback commented Nov 5, 2013

maybe make a separate section in v0.13 to highlite this (with an example like this)

@jtratner
Copy link
Contributor Author

jtratner commented Nov 5, 2013

yep, just did that.

On Tue, Nov 5, 2013 at 7:16 AM, jreback [email protected] wrote:

maybe make a separate section in v0.13 to highlite this (with an example
like this)


Reply to this email directly or view it on GitHubhttps://github.com//pull/5439#issuecomment-27768032
.

@jreback
Copy link
Contributor

jreback commented Nov 5, 2013

looks ok to me

jtratner added a commit that referenced this pull request Nov 5, 2013
ENH: Always do true division on Python 2.X
@jtratner jtratner merged commit 05cb960 into pandas-dev:master Nov 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Change NDFrame.div() to be truediv in Python 2.X
2 participants